package me.skean.synologyphotosutil.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Tag;
import me.skean.synologyphotosutil.OperationService;
import me.skean.synologyphotosutil.bean.PhotosRes;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;

@Api(tags = "图片管理")
@RestController
@RequestMapping("/photos")
@ApiSupport(order = 20)
public class PhotosController {
    @Resource
    private OperationService service;

    @ApiOperationSupport(order = 21)
    @PostMapping(value = "/queryDuplicate", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询重复")
    public ResponseEntity<PhotosRes> queryDuplicate(
            @ApiParam(value = "目录路径")
            @RequestParam(value = "path", required = false)
            String path) {
        return ResponseEntity.ok(service.photoOperation(path, false));
    }

    @ApiOperationSupport(order = 25)
    @PostMapping(value = "/deleteDuplicate", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除重复")
    public ResponseEntity<PhotosRes> deleteDuplicate(
            @ApiParam(value = "目录路径")
            @RequestParam(value = "path", required = false)
            String path) {
        return ResponseEntity.ok(service.photoOperation(path, true));
    }

}
